From 2d2f9861a6630668587f0d4f67098fc1ec2cf8e8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 13 May 2014 20:36:02 -0400 Subject: [PATCH] inspector: Show GAction information Show the actions that are added to GtkApplication and GtkApplicationWindows, as well as action groups that are inserted elsewhere with gtk_widget_insert_action_group. https://bugzilla.gnome.org/show_bug.cgi?id=730095 --- gtk/inspector/Makefile.am | 3 + gtk/inspector/actions.c | 131 ++++++++++++++++++++++++++ gtk/inspector/actions.h | 55 +++++++++++ gtk/inspector/actions.ui | 103 ++++++++++++++++++++ gtk/inspector/init.c | 2 + gtk/inspector/inspector.gresource.xml | 1 + gtk/inspector/window.c | 4 + gtk/inspector/window.h | 1 + gtk/inspector/window.ui | 10 ++ po/POTFILES.in | 1 + 10 files changed, 311 insertions(+) create mode 100644 gtk/inspector/actions.c create mode 100644 gtk/inspector/actions.h create mode 100644 gtk/inspector/actions.ui diff --git a/gtk/inspector/Makefile.am b/gtk/inspector/Makefile.am index 4ca2cdd628..d1d570653a 100644 --- a/gtk/inspector/Makefile.am +++ b/gtk/inspector/Makefile.am @@ -15,6 +15,8 @@ BUILT_SOURCES = \ resources.c libgtkinspector_la_SOURCES = \ + actions.h \ + actions.c \ button-path.h \ button-path.c \ classes-list.h \ @@ -74,6 +76,7 @@ libgtkinspector_la_LDFLAGS = \ $(LDFLAGS) templates = \ + actions.ui \ button-path.ui \ classes-list.ui \ css-editor.ui \ diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c new file mode 100644 index 0000000000..8b1e31aeaa --- /dev/null +++ b/gtk/inspector/actions.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2014 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "config.h" +#include +#include "actions.h" +#include "gtkwidgetprivate.h" + +enum +{ + COLUMN_PREFIX, + COLUMN_NAME, + COLUMN_ENABLED, + COLUMN_PARAMETER, + COLUMN_STATE +}; + +struct _GtkInspectorActionsPrivate +{ + GtkListStore *model; + GtkWidget *prefix_label; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_BOX) + +static void +gtk_inspector_actions_init (GtkInspectorActions *sl) +{ + sl->priv = gtk_inspector_actions_get_instance_private (sl); + gtk_widget_init_template (GTK_WIDGET (sl)); +} + +static void +add_actions (GtkInspectorActions *sl, + const gchar *prefix, + GActionGroup *group) +{ + GtkTreeIter iter; + gint i; + gchar **names; + gboolean enabled; + const gchar *parameter; + GVariant *state; + gchar *state_string; + + gtk_widget_show (GTK_WIDGET (sl)); + + names = g_action_group_list_actions (group); + for (i = 0; names[i]; i++) + { + enabled = g_action_group_get_action_enabled (group, names[i]); + parameter = (const gchar *)g_action_group_get_action_parameter_type (group, names[i]); + state = g_action_group_get_action_state (group, names[i]); + if (state) + state_string = g_variant_print (state, FALSE); + else + state_string = g_strdup (""); + gtk_list_store_append (sl->priv->model, &iter); + gtk_list_store_set (sl->priv->model, &iter, + COLUMN_PREFIX, prefix, + COLUMN_NAME, names[i], + COLUMN_ENABLED, enabled, + COLUMN_PARAMETER, parameter, + COLUMN_STATE, state_string, + -1); + g_free (state_string); + } + g_strfreev (names); +} + +void +gtk_inspector_actions_set_object (GtkInspectorActions *sl, + GObject *object) +{ + gtk_list_store_clear (sl->priv->model); + gtk_widget_hide (GTK_WIDGET (sl)); + + if (GTK_IS_APPLICATION (object)) + add_actions (sl, "app", G_ACTION_GROUP (object)); + else if (GTK_IS_APPLICATION_WINDOW (object)) + add_actions (sl, "win", G_ACTION_GROUP (object)); + else if (GTK_IS_WIDGET (object)) + { + gchar **prefixes; + GActionGroup *group; + gint i; + + prefixes = _gtk_widget_list_action_prefixes (GTK_WIDGET (object)); + if (prefixes) + { + for (i = 0; prefixes[i]; i++) + { + group = _gtk_widget_get_action_group (GTK_WIDGET (object), prefixes[i]); + add_actions (sl, prefixes[i], group); + } + g_free (prefixes); + } + } +} + +static void +gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/actions.ui"); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, model); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, prefix_label); +} + +GtkWidget * +gtk_inspector_actions_new (void) +{ + return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_ACTIONS, NULL)); +} + +// vim: set et sw=2 ts=2: diff --git a/gtk/inspector/actions.h b/gtk/inspector/actions.h new file mode 100644 index 0000000000..050f3c2e5b --- /dev/null +++ b/gtk/inspector/actions.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef _GTK_INSPECTOR_ACTIONS_H_ +#define _GTK_INSPECTOR_ACTIONS_H_ + +#include + +#define GTK_TYPE_INSPECTOR_ACTIONS (gtk_inspector_actions_get_type()) +#define GTK_INSPECTOR_ACTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_ACTIONS, GtkInspectorActions)) +#define GTK_INSPECTOR_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_ACTIONS, GtkInspectorActionsClass)) +#define GTK_INSPECTOR_IS_ACTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_ACTIONS)) +#define GTK_INSPECTOR_IS_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_ACTIONS)) +#define GTK_INSPECTOR_ACTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_ACTIONS, GtkInspectorActionsClass)) + + +typedef struct _GtkInspectorActionsPrivate GtkInspectorActionsPrivate; + +typedef struct _GtkInspectorActions +{ + GtkBox parent; + GtkInspectorActionsPrivate *priv; +} GtkInspectorActions; + +typedef struct _GtkInspectorActionsClass +{ + GtkBoxClass parent; +} GtkInspectorActionsClass; + +G_BEGIN_DECLS + +GType gtk_inspector_actions_get_type (void); +GtkWidget *gtk_inspector_actions_new (void); +void gtk_inspector_actions_set_object (GtkInspectorActions *sl, + GObject *object); + +G_END_DECLS + +#endif // _GTK_INSPECTOR_ACTIONS_H_ + +// vim: set et sw=2 ts=2: diff --git a/gtk/inspector/actions.ui b/gtk/inspector/actions.ui new file mode 100644 index 0000000000..cdc92b9413 --- /dev/null +++ b/gtk/inspector/actions.ui @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c index 528e0eb778..027f374c2a 100644 --- a/gtk/inspector/init.c +++ b/gtk/inspector/init.c @@ -22,6 +22,7 @@ */ #include +#include "actions.h" #include "button-path.h" #include "classes-list.h" #include "css-editor.h" @@ -47,6 +48,7 @@ gtk_inspector_init (void) gtk_inspector_register_resource (); + g_type_ensure (GTK_TYPE_INSPECTOR_ACTIONS); g_type_ensure (GTK_TYPE_INSPECTOR_BUTTON_PATH); g_type_ensure (GTK_TYPE_INSPECTOR_CLASSES_LIST); g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR); diff --git a/gtk/inspector/inspector.gresource.xml b/gtk/inspector/inspector.gresource.xml index fb65fad987..74081fbc1b 100644 --- a/gtk/inspector/inspector.gresource.xml +++ b/gtk/inspector/inspector.gresource.xml @@ -1,6 +1,7 @@ + actions.ui button-path.ui classes-list.ui css-editor.ui diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c index f1928b6e04..0bcf066928 100644 --- a/gtk/inspector/window.c +++ b/gtk/inspector/window.c @@ -38,6 +38,8 @@ #include "data-list.h" #include "themes.h" #include "signals-list.h" +#include "actions.h" + G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW) @@ -71,6 +73,7 @@ on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt, gtk_inspector_classes_list_set_object (GTK_INSPECTOR_CLASSES_LIST (iw->classes_list), selected); gtk_inspector_css_editor_set_object (GTK_INSPECTOR_CSS_EDITOR (iw->widget_css_editor), selected); gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected); + gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected); if (GTK_IS_WIDGET (selected)) gtk_inspector_flash_widget (iw, GTK_WIDGET (selected)); } @@ -168,6 +171,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass) gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, python_shell); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_popup); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list); + gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions); gtk_widget_class_bind_template_callback (widget_class, on_inspect); gtk_widget_class_bind_template_callback (widget_class, on_widget_tree_selection_changed); diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h index da2742fe42..2621f26a1a 100644 --- a/gtk/inspector/window.h +++ b/gtk/inspector/window.h @@ -51,6 +51,7 @@ typedef struct GtkWidget *widget_css_editor; GtkWidget *object_hierarchy; GtkWidget *data_list; + GtkWidget *actions; GtkWidget *widget_popup; diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui index f8007b28c2..238bd362d5 100644 --- a/gtk/inspector/window.ui +++ b/gtk/inspector/window.ui @@ -182,6 +182,16 @@ Data + + + + + + + True + Actions + + True diff --git a/po/POTFILES.in b/po/POTFILES.in index 3e33f4e90c..574db4b672 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -268,6 +268,7 @@ gtk/gtkviewport.c gtk/gtkvolumebutton.c gtk/gtkwidget.c gtk/gtkwindow.c +gtk/inspector/actions.ui.h gtk/inspector/button-path.ui.h gtk/inspector/classes-list.c gtk/inspector/classes-list.ui.h -- 2.30.2